package ${package}.${moduleName}.service.impl;

import cn.com.pg.instore.core.common.dto.PageDto;
import cn.com.pg.instore.core.common.dto.PageDtoUtil;
import lombok.RequiredArgsConstructor;
import ${package}.${moduleName}.convertor.${ClassName}Convertor;
import ${package}.${moduleName}.entity.${ClassName};
import ${package}.${moduleName}.query.${ClassName}Query;
import ${package}.${moduleName}.service.api.dto.${ClassName}Dto;
import ${package}.${moduleName}.mapper.${ClassName}Mapper;
import ${package}.${moduleName}.respository.${ClassName}Repository;
import ${package}.${moduleName}.service.${ClassName}Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ${tableComment}
 *
* @author ${author}
* @since ${date}
 */
@Service
@RequiredArgsConstructor
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements ${ClassName}Service {
    
    private final ${ClassName}Repository ${className}Repository;
    private final ${ClassName}Convertor ${className}Convertor;


    @Override
    public PageDto<${ClassName}Dto> page(${ClassName}Query query) {
        Page<${ClassName}> page = ${className}Repository.page(query); 
        List<${ClassName}Dto> records = ${className}Convertor.convertToDtoList(page.getRecords());
        return PageDtoUtil.generatePageDto(page.getTotal(), page.getSize(), page.getCurrent(), page.getTotal(), records);
    }
        
    @Override
    public ${ClassName}Dto get${ClassName}ById(String id){
        return ${className}Convertor.convertToDto(${className}Repository.get${ClassName}ById(id));
    }

        
    @Override
    public Boolean save${ClassName}(${ClassName}Dto dto) {
        return ${className}Repository.save${ClassName}(${className}Convertor.convertToEntity(dto)) > 0;
    }

    @Override
    public Boolean update${ClassName}(${ClassName}Dto dto) {
        return ${className}Repository.update${ClassName}(${className}Convertor.convertToEntity(dto)) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteByIds(List<String> ids) {
        return ${className}Repository.deleteByIds(ids) > 0;
    }

}